package school.model.dao;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import school.domain.Student;

@Repository
public class StudentDAOImpl implements StudentDAO{
	
	@Autowired
	private SqlSessionTemplate sqlSession;

	@Override
	public int insertStudent(Student student) {
		
		return sqlSession.insert(makeSqlId("insertStudent"), student);
	}

	@Override
	public int updateStudent(Student student) {
		
		return sqlSession.update(makeSqlId("updateStudent"), student);
	}

	@Override
	public int deleteStudentById(String studentId) {
		
		return sqlSession.delete(makeSqlId("deleteStudentById"), studentId);
	}

	@Override
	public Student selectStudentById(String studentId) {
		
		return sqlSession.selectOne(makeSqlId("selectStudentById"), studentId);
	}

	@Override
	public List<Student> selectStudentList() {
		
		return sqlSession.selectList(makeSqlId("selectStudentList"));
	}

	@Override
	public List<Student> selectStudentByAddress(String studentAddress) {
		
		return sqlSession.selectList(makeSqlId("selectStudentByAddress"), studentAddress);
	}

	@Override
	public List<Student> selectStudentByStudentYear(int schoolYear) {
		
		return sqlSession.selectList(makeSqlId("selectStudentByStudentYear"), schoolYear);
	}
	private String makeSqlId(String id){
		return "school.manager.student."+id;
	}
	
}
